/**
 * 
 */
package by.myteam.library.command;

import java.util.List;

import by.myteam.library.bo.Book;
import by.myteam.library.storage.IStorageProvider;
import by.myteam.library.storage.StorageFactory;
import by.myteam.library.storage.StorageFactory.StorageType;

/**
 * @author IstiN
 *
 */
public class AddCommand implements ICommand {

	private static final String ADD = "add";
	
	private static final String INFO = "add new book to library";

	/* (non-Javadoc)
	 * @see by.myteam.library.command.ICommand#name()
	 */
	@Override
	public String name() {
		return ADD;
	}

	/* (non-Javadoc)
	 * @see by.myteam.library.command.ICommand#info()
	 */
	@Override
	public String info() {
		return INFO;
	}

	/* (non-Javadoc)
	 * @see by.myteam.library.command.ICommand#execute(java.lang.String)
	 */
	@Override
	public void execute(String... data) {
		StorageType storageType = null;
		try {
			storageType = StorageFactory.StorageType.valueOf(data[1]);	
		} catch (IllegalArgumentException e) {
			// TODO: handle exception
			System.out.println("used default storage type");
		}
		if (storageType == null) {
			List<IStorageProvider> listStorageProviders = StorageFactory.getFactory().getListStorageProviders();
			for (IStorageProvider storageProvider : listStorageProviders) {
				storageProvider.addBook(new Book());
			}
		} else {
			storageType.getProvider().addBook(new Book());
		}
	}

}
